package com.zxp01.selenium;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

/*熟悉alert弹窗*/
public class Z04_Alert {
    WebDriver driver =new ChromeDriver();
    @Test
    public void alertDemo() throws InterruptedException {
        //定位普通div弹窗,直接定位
        driver.manage().window().maximize();
        driver.get("https://www.baidu.com/");
        driver.findElement(By.id("s-usersetting-top")).click();
        driver.findElement(By.xpath("//*[@id=\"s-user-setting-menu\"]/div/a[1]/span")).click();
        Thread.sleep(1000);
        driver.findElement(By.linkText("保存设置")).click();

        //定位alert弹窗
        Thread.sleep(2000);
        Alert alert =driver.switchTo().alert();
//        alert.accept();     //确定
        System.out.println(alert.getText());    //获取弹框的内容
        alert.dismiss();     //取消

        Thread.sleep(2000);
        driver.quit();
    }
}
